import request from '@/api/axios'
import {AxiosPromise} from 'axios'
import {DataRes, Paging} from '@/api/config'

// 列表数据
export interface SearchData extends Paging{
  instrumentName:string, // 仪器名称
  companyId:number|string, // 生产厂家id
  model:string, // 仪器型号
  instrumentType:number // 仪器分类编码
  instrumentClass:string//检验仪器类型
}

// 列表数据
export interface SearchData1{
  instrumentName:string, // 仪器名称
  companyId:number|string, // 生产厂家id
  model:string, // 仪器型号
  instrumentClass:string//仪器分类
  instrumentType:number // 仪器分类编码
}

// 列表数据
export interface TableData{
  instrumentName?:string, // 仪器名称
  instrumentCode?:string, // 仪器编码
  companyName?:string, // 仪器生产厂家
  model?:string, //	仪器型号
  reagentNames?:string, //关联试剂
  instrumentTypeName?:string
  instrumentClass?:string
  operation?:any
}

// 下来数据
export interface ClassData{
  dictItemCode?:string,
  dictItemName?:string,
  value?:string|number,
  label?:string|number
}

// 关联试剂数据
export interface ReagentData{
  id:string,
  consumableProductName:string,
  value?:string|number,
  label?:string|number
}
// 关联生产厂家数据
export interface mechanismData{
  orgCode:string,
  orgGradeName:string,
  orgName:string,
  id:string,
  value?:string|number,
  label?:string|number
}
// 关联生产厂家数据
export interface SaveData{
  instrumentId?:string,
  instrumentName?:string, // 仪器名称
  instrumentType?:number, // 仪器分类编码
  instrumentClass?:string, //检验仪器类型
  reagents?:Array<string>, // 选择的试剂数组
  companyId?:string, // 生产厂家id
  specimenRule:string//标本号规则
  maxSpecimen?:string//最大标本号
  id?:string,
  brandType?:string, // 品牌类型编码:进口/合资等
  model?:string,
  communicationType?:number,
  networkInterface?:string,
  serverPort?:string,
  serverIp?:string,
  serialPortName?:string,
  baudRate?:string,
  checkBit?:string,
  dataBit?:string,
  stopBit?:string,
  databaseType?:string,
  databaseAddress?:string,
  username?:string,
  password?:string,
  coding?:string,
  readFrequency?:string,
  filePath?:string,
  sampleType?:string, // 标本类型
}
// 维护子项搜索数据
export interface ItemLists{
  instrumentId:string,
  inspectItemName?:string, // 仪器名称
  inspectItemType?:string, // 仪器分类编码
  inspectFunctionCode?:string // 选择的试剂数组
  inspectItemCode?:string
  inspectMethod?:string
  keywords?:string
}

// 维护子项搜索数据
export interface ItemList extends Paging{
  instrumentId:string,
  inspectItemName?:string, // 仪器名称
  inspectItemType?:string, // 仪器分类编码
  inspectFunctionCode?:string // 选择的试剂数组
  inspectItemCode?:string
  inspectMethod?:string
}

// 维护子项列表数据
export interface ItemData{
  id:string,
  inspectItemCode:string, // 仪器名称
  inspectItemName:string, // 仪器分类编码
  englishName:string, // 选择的试剂数组
  inspectItemType:string,
  inspectFunctionCode:string,
  inspectItemId?:string,
  calOptions?:string,
  operation?:any
}

// 仪器生产厂家下拉数据数据
export interface SearchableData{
  orgId:string, // 仪器名称
  orgName:string, // 仪器分类编码
  value?:string|number,
  label?:string|number
}
// 仪器生产厂家下拉数据数据
export interface InspectItemListAdd{
  id:string,
  inspectItemCode:string, // 检验子项编码
  inspectItemName:string, // 检验子项名称
  operation?:any
}

// 为仪器维护检验子项
export interface SetInspectItemData{
  instrumentId:string,
  inspects:Array<string> // 检验子项编码
}

// 为仪器维护检验子项
export interface ExceptIdsData{
  exceptIds:any,
  inspectItemType?:string,
  keywords:string
}

// 查询仪器检验子项的参考范围
export interface ReferenceRangeData{
  instrumentId:string,
  inspectItemId:string,
  reagentId:string|null
}


// //仪器设备列表数据
// export const instrumentpage = (params:SearchData):AxiosPromise<DataRes<Array<TableData>>> => {
//   return request({
//     url:'/api/platform-data/instrument/page',
//     method:'get',
//     params
//   })
// }
export interface itemInforList {
  size:number
  total:number
  records:Array<TableData>
}
//检验仪器设备列表数据  改
export const instrumentpage = (params:SearchData):AxiosPromise<DataRes<itemInforList>> => {
  return request({
    url:'/api/instrument/page',
    method:'get',
    params
  })
}
//关联试剂查询
// export const opationalReagent = ():AxiosPromise<DataRes<Array<ReagentData>>> => {
//   return request({
//     url:'/api/platform-data/reagent/get/opational/reagent',
//     method:'get'
//   })
// }

// 8.25
export const opationalReagent = ():AxiosPromise<DataRes<Array<ReagentData>>> => {
  return request({
    url:'/api/platform-data/consumableArchive/getAllReagent',
    method:'get'
  })
}

//机构列表
// export const mechanismList = ():AxiosPromise<DataRes<Array<mechanismData>>> => {
//   return request({
//     url:'/api/platform-system/organization/get/all',
//     method:'get'
//   })
// }

// 8.25
export const mechanismList = ():AxiosPromise<DataRes<Array<mechanismData>>> => {
  return request({
    url:'/api/platform-system/manufacturer/getAll',
    method:'get'
  })
}

//新增或修改仪器知识库信息
export const instrumentSave = (data:SaveData):AxiosPromise<DataRes<undefined>> => {
  return request({
    url:'/api/instrument/save',
    method:'post',
    data
  })
}

// //查询仪器的检验子项
// export const inspectItemList = (params:ItemLists):AxiosPromise<DataRes<Array<any>>> => {
//   return request({
//     url:'/api/platform-data/instrument/inspectItem/list',
//     method:'get',
//     params
//   })
// }
export interface itemInspectItemList {
  size:number
  total:number
  records:Array<any>
}
//查询仪器的检验子项  维护检验设备分页
export const inspectItemList = (params:ItemLists):AxiosPromise<DataRes<itemInspectItemList>> => {
  return request({
    url:'/api/instrument/item/page',
    method:'get',
    params
  })
}
//查询仪器的检验子项  维护参考区间列表
export const inspectItemListCanKao = (params:ItemLists):AxiosPromise<DataRes<itemInspectItemList>> => {
  return request({
    url:'/api/instrument/inspectItem/list',
    method:'get',
    params
  })
}

export interface AllByOrgId extends Paging{
  orgId:string
  name?:string|null
}
// 查询仪器的检验子项(部署的右侧分页)
export const inspectItemPage = (params:AllByOrgId):AxiosPromise<DataRes<Array<any>>> => {
  return request({
    url:'/api/platform-data/labInstrument/list/item',
    method:'get',
    params
  })
}
//供应商下拉数据
export const searchableList = ():AxiosPromise<DataRes<Array<SearchableData>>> => {
  return request({
    url:'/api/platform-system/supplier/get/ten/searchable',
    method:'get'
  })
}
//删除
export const instrumentDelete = (data:{id:string}):AxiosPromise<DataRes<Array<SearchableData>>> => {
  return request({
    url:'/api/instrument/remove/' + data.id,
    method:'post'
  })
}
// //根据条件查询所有子项
// export const inspectItemListAdd = (params:ExceptIdsData):AxiosPromise<DataRes<Array<InspectItemListAdd>>> => {
//   console.log(params, '---params----')
//   return request({
//     url:'/api/platform-data/inspectItem/list',
//     method:'get',
//     params
//   })
// }
// 为仪器维护检验子项
export interface ExceptIdsDataNew{
  instrumentId:string,
  checkType:string,
}
//根据条件查询所有子项  改
export const inspectItemListAdd = (params:ExceptIdsDataNew):AxiosPromise<DataRes<Array<InspectItemListAdd>>> => {
  // console.log(params, '---params----')
  return request({
    url:'/api/item/list',
    method:'get',
    params
  })
}

//为仪器维护检验子项
export const setInspectItem = (data:SetInspectItemData):AxiosPromise<DataRes<Array<InspectItemListAdd>>> => {
  return request({
    url:'/api/platform-data/instrument/setInspectItem',
    method:'post',
    data
  })
}

//为仪器维护检验子项保存
export const inspectItemSave = (data:SetInspectItemData):AxiosPromise<DataRes<Array<InspectItemListAdd>>> => {
  return request({
    url:'/api/instrument/inspectItem/save',
    method:'post',
    data
  })
}

// 查询仪器检验子项的参考范围
export interface ReferenceRangeDataList{
  instrumentId:string,
  itemId:string
}

//查询仪器检验子项的参考范围
export const referenceRangeList = (params:ReferenceRangeDataList):AxiosPromise<DataRes<Array<InspectItemListAdd>>> => {
  return request({
    url:'/api/instrument/referenceRange/list',
    method:'get',
    params
  })
}

//保存参考范围
export const referenceRangeSave = (data:any):AxiosPromise<DataRes<Array<InspectItemListAdd>>> => {
  return request({
    url:'/api/instrument/referenceRange/save',
    method:'post',
    data
  })
}


//根据id删除参考范围
export const referenceRangeDelete = (data:{id:string}):AxiosPromise<DataRes<Array<InspectItemListAdd>>> => {
  return request({
    url:'/api/instrument/referenceRange/remove/' + data.id,
    method:'post',
    data
  })
}

//根据仪器id与检验子项id删除它们的关系
// instrumentId	仪器 idinspectItemId	检验子项id
export const inspectItemDelete = (data:{instrumentId:string, inspectItemId:string}):AxiosPromise<DataRes<Array<InspectItemListAdd>>> => {
  return request({
    url:'/api/instrument/inspectItem/remove/' + data.instrumentId + '/' + data.inspectItemId,
    method:'post',
    data
  })
}

//获取专业组接口  废弃
export const userDisciplines = ():AxiosPromise<DataRes<Array<any>>> => {
  return request({
    url:'/api/platform-data/disciplineDeploy/user/disciplines',
    method:'get'
  })
}

//维护质控品获取右侧所有数据
export const qcMaterialList = ():AxiosPromise<DataRes<Array<any>>> => {
  return request({
    url:'/api/platform-data/qcMaterial/list',
    method:'get'
  })
}
//维护质控品获取右侧所有数据8.25
export const consumableArchiveList = ():AxiosPromise<DataRes<Array<any>>> => {
  return request({
    url:'/api/platform-data/consumableArchive/getAllReagent',
    method:'get'
  })
}

//维护质控品获取左侧侧所有数据
export const labInstrumentList = (params:{id:string}):AxiosPromise<DataRes<Array<any>>> => {
  return request({
    url:'/api/platform-data/labInstrument/qc/list/' + params.id,
    method:'get'
  })
}

//批量设置仪器的质控品和质控品与检验子项的关系
export const labInstrumentSave = (data:any):AxiosPromise<DataRes<Array<any>>> => {
  return request({
    url:'/api/platform-data/labInstrument/qc/save',
    method:'post',
    data
  })
}

//获取标本类型 2022-7-22 原本是字典中取值 后修改为取自检验知识库 标本类型
export const sampleTypeList = ():AxiosPromise<DataRes<Array<any>>> => {
  return request({
    url:'/api/platform-data/sampleType/list',
    method:'get'
  })
}

// 获取子页面数据8.25
export const getAllData = (instrumentId:string):AxiosPromise<DataRes<SaveData>> => {
  return request({
    url:`/api/instrument/detail/${instrumentId}`,
    method:'get'
  })
}
export const getAllVerData = (instrumentId:string):AxiosPromise<DataRes<SaveData>> => {
  return request({
    url:`/api/platform-data/instrument/detail/ver/${instrumentId}`,
    method:'get'
  })
}



export interface SaveComunite{
  instrumentId?:string,
  labInstrumentId?:string, // 仪器部署id
  id?:string,
  communicationType?:string,
  networkInterface?:string,
  serverPort?:string,
  serverIp?:string,
  serialPortName?:string,
  baudRate?:string,
  checkBit?:string,
  dataBit?:string,
  stopBit?:string,
  databaseType?:string,
  databaseAddress?:string,
  username?:string,
  password?:string,
  coding?:string,
  readFrequency?:string,
  filePath?:string,
}

//获取仪器部署通讯详情
export const getAllComunite = (labInstrumentId:string):AxiosPromise<DataRes<SaveComunite>> => {
  return request({
    url:`/api/platform-data/labInstrumentProtocol/detail/${labInstrumentId}`,
    method:'get'
  })
}


//保存通讯
export const comuniteSave = (data:SaveComunite):AxiosPromise<DataRes<any>> => {
  return request({
    url:'/api/platform-data/labInstrumentProtocol/saveOrUpdate',
    method:'post',
    data
  })
}

//批量设置检验子项的通道号
export const inspectItemChannel = (data:any):AxiosPromise<DataRes<undefined>> => {
  return request({
    url:'/api/instrument/item/channel',
    method:'post',
    data
  })
}
export interface itemInspectItemListChannel {
  size:number
  total:number
  records:Array<any>
}
//查询仪器的检验子项  维护检验设备分页
export const inspectItemListChannel = (params:ItemLists):AxiosPromise<DataRes<any>> => {
  return request({
    url:'/api/instrument/inspectItem/list',
    method:'get',
    params
  })
}